// 层序遍历
function  flatMap(head){
    const res = [], queue = [head];
    while(queue.length){
        const length = queue.length, map = [];
        for(let i = 0; i < length; i++){
            const node = queue.shift()
            map.push(node.val)
            node.left && queue.push(node.left)
            node.right && queue.push(node.right)
        }
        res.push(map)
    }
    return res
}

